//
//  RootViewController.m
//  FineNurse
//
//  Created by TT_UED on 2018/4/13.
//  Copyright © 2018年 TT_UED. All rights reserved.
//

#import "RootViewController.h"
#import "TabSettingViewController.h"
#import "TabTweetViewController.h"
#import "ScmRepairTableViewController.h"
#import "MeetingRoomViewController.h"
#import "ApiDefine.h"

@interface RootViewController ()


@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
 
    NSLog(@"API_ULR 2018:%@",ApiLogin);
    
    ScmRepairTableViewController *newsSVC = [[ScmRepairTableViewController alloc] init];
    
    TabTweetViewController *tweetVC = [[TabTweetViewController alloc] init];
    
    
    
   //  _navigationDelegate = [[OSCCoustomNavigationDelegate alloc] init];
    

    MeetingRoomViewController *meetingroom = [[MeetingRoomViewController alloc] init];
    UINavigationController *discoverNav = [[UINavigationController alloc] initWithRootViewController:meetingroom];
 
    
    TabSettingViewController *homepageNav = [[TabSettingViewController alloc] init];

    
    self.tabBar.translucent = NO;
    self.viewControllers = @[
                             [self addNavigationItemForViewController:newsSVC],
                             [self addNavigationItemForViewController:tweetVC],
                             [UIViewController new],
                             discoverNav,
                             [self addNavigationItemForViewController:homepageNav]
                             ];
    
    NSArray *titles = @[@"综合", @"动弹", @"", @"发现", @"我的"];
    NSArray *images = @[@"tabbar-news", @"tabbar-tweet", @"", @"tabbar-discover", @"tabbar-me"];
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem *item, NSUInteger idx, BOOL *stop) {
        [item setTitle:titles[idx]];
        item.image = [[UIImage imageNamed:images[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage = [[UIImage imageNamed:[images[idx] stringByAppendingString:@"-selected"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }];
    [self.tabBar.items[2] setEnabled:NO];
    
   // [self addCenterButtonWithImage:[UIImage imageNamed:@"ic_nav_add"]];//@"tabbar-more"]];
    
//    [self.tabBar addObserver:self
//                  forKeyPath:@"selectedItem"
//                     options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew
//                     context:nil];
    
    // 功能键相关
//    _optionButtons = [NSMutableArray new];
//    _screenHeight = [UIScreen mainScreen].bounds.size.height;
//    _screenWidth  = [UIScreen mainScreen].bounds.size.width;
//    _length = 60;        // 圆形按钮的直径
//    _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
    
    NSArray *buttonTitles = @[@"文字", @"相册", @"拍照", @"语音", @"扫一扫", @"找人"];
    NSArray *buttonImages = @[@"tweetEditing", @"picture", @"shooting", @"sound", @"scan", @"search"];
    int buttonColors[] = {0xe69961, 0x0dac6b, 0x24a0c4, 0xe96360, 0x61b644, 0xf1c50e};
    
//    for (int i = 0; i < 6; i++) {
//        OptionButton *optionButton = [[OptionButton alloc] initWithTitle:buttonTitles[i]
//                                                                   image:[UIImage imageNamed:buttonImages[i]]
//                                                                andColor:[UIColor colorWithHex:buttonColors[i]]];
//        
//        optionButton.frame = CGRectMake((_screenWidth/6 * (i%3*2+1) - (_length+16)/2),
//                                        _screenHeight + 150 + i/3*100,
//                                        _length + 16,
//                                        _length + [UIFont systemFontOfSize:14].lineHeight + 24);
//        [optionButton.button setCornerRadius:_length/2];
//        
//        optionButton.tag = i;
//        optionButton.userInteractionEnabled = YES;
//        [optionButton addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapOptionButton:)]];
//        
//        [self.view addSubview:optionButton];
//        [_optionButtons addObject:optionButton];
//    }
//
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




- (UINavigationController *)addNavigationItemForViewController:(UIViewController *)viewController
{
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    
    viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
                                                                                                     target:self
                                                                                                     action:@selector(pushSearchViewController)];
    
    
    return navigationController;
}

- (void)pushSearchViewController
{
    UINavigationController *nav = (UINavigationController *)self.selectedViewController;
    UIViewController *searchVC = [[UIViewController alloc] init];
    
    
    UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:searchVC];
    [nav presentViewController:searchNav animated:YES completion:^{
        
    }];
}


@end
